package team.pwy.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team.pwy.mapper.TypeMapper;
import team.pwy.pojo.entity.Movie;
import team.pwy.pojo.entity.Type;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 本来用来演示:
 *
 * @author feng
 * @date 2023/10/9
 * @Description
 */
@Service
@Transactional
public class TypeServerImpl implements TypeServer{
    @Autowired
    private TypeMapper typeMapper;
    @Autowired
    private MovieService movieService;
    @Override
    public List<Movie> findByType(String type) {
        Map<String,String> map = new HashMap<>();
        map.put(type,type);
       List<Integer> id=typeMapper.findByType(map);
        List<Movie> list=new ArrayList<>();
        for (Integer ids:id) {
            Movie movie1=movieService.findById(ids);
            list.add(movie1);
        }
        return list;
    }

    @Override
    public Type findByMovieId(Integer movieId) {
        return typeMapper.findByMovieId(movieId);
    }
}
